import httplib2
import cookielib
import urllib2
import urllib
import httplib

def main():
    headers = {"user-agent":"Chrome 16"}
    http = httplib2.Http()
    resp, content = http.request(r"http://www.baidu.com", "GET", headers=headers)
    Cookies = resp["set-cookie"]
    fp = open("Cookies.txt", "wb+")
    print >> fp, Cookies
    print Cookies
    fp.close()

def url2cookie(url):
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    r = opener.open(url)
    r.close()


if __name__ == "__main__":
    url2cookie(r"http://www.bing.com/")
